#encoding:utf-8

import unittest
from hero import *
from equip import *

class TestEquip(unittest.TestCase):
    
    def setUp(self):
        player1 = Hero(name=u"狄洛",vitality=20,power=20,strength=20,intellect=10,speed=10)
        self.player1 = player1
        
    def test_setEquip(self):
        '''装备安装后人物属性值变化测试'''
        self.player1.setEquip(Equips(0, name=u'长剑', level=1, atk=10))       #装备长剑
        self.assertEqual(self.player1.maxhp, 400)
        self.assertEqual(self.player1.maxmp,270)
        self.assertEqual(int(self.player1.atk),69)
        self.assertEqual(int(self.player1.defend),55)
        self.assertEqual(int(self.player1.dexterity),38)
        self.assertEqual(int(self.player1.magic),35)
        
        self.player1.setEquip(Equips(1, name=u'帽子', level=1, defend=1))         #装备帽子
        self.assertEqual(self.player1.maxhp, 400)
        self.assertEqual(self.player1.maxmp,270)
        self.assertEqual(int(self.player1.atk),69)
        self.assertEqual(int(self.player1.defend),56)
        self.assertEqual(int(self.player1.dexterity),38)
        self.assertEqual(int(self.player1.magic),35)
        
        self.player1.setEquip(Equips(2, name=u'肩膀', level=1, atk=2, defend=2))      #装备肩膀
        self.assertEqual(self.player1.maxhp, 400)
        self.assertEqual(self.player1.maxmp,270)
        self.assertEqual(int(self.player1.atk),71)
        self.assertEqual(int(self.player1.defend),58)
        self.assertEqual(int(self.player1.dexterity),38)
        self.assertEqual(int(self.player1.magic),35)
        
        self.player1.setEquip(Equips(3, name=u'衣服', level=1, vitality=1, maxhp=20, defend=2))       #装备衣服
        self.assertEqual(self.player1.maxhp, 428)
        self.assertEqual(self.player1.maxmp,271)
        self.assertEqual(int(self.player1.atk),71)
        self.assertEqual(int(self.player1.defend),60)
        self.assertEqual(int(self.player1.dexterity),38)
        self.assertEqual(int(self.player1.magic),35)
        
        self.player1.setEquip(Equips(4, name=u'裤子', level=1, strength=2, intellect=1))      #装备裤子
        self.assertEqual(self.player1.maxhp, 435)
        self.assertEqual(self.player1.maxmp,285)
        self.assertEqual(int(self.player1.atk),71)
        self.assertEqual(int(self.player1.defend),64)
        self.assertEqual(int(self.player1.dexterity),38)
        self.assertEqual(int(self.player1.magic),37)
        
        self.player1.setEquip(Equips(5, name=u'鞋子', level=1, speed=2, strength=2))      #装备鞋子
        self.assertEqual(self.player1.maxhp, 447)
        self.assertEqual(self.player1.maxmp,293)
        self.assertEqual(int(self.player1.atk),72)
        self.assertEqual(int(self.player1.defend),68)
        self.assertEqual(int(self.player1.dexterity),43)
        self.assertEqual(int(self.player1.magic),38)

    
    def test_delEquip(self):
        '''装备卸载后人物属性值变化测试'''
        self.player1.setEquip(Equips(0, name=u'长剑', level=1, atk=10))
        self.player1.setEquip(Equips(1, name=u'帽子', level=1, defend=1))
        self.player1.setEquip(Equips(2, name=u'肩膀', level=1, atk=2, defend=2))
        self.player1.setEquip(Equips(3, name=u'衣服', level=1, vitality=1, maxhp=20, defend=2))
        self.player1.setEquip(Equips(4, name=u'裤子', level=1, strength=2, intellect=1))
        self.player1.setEquip(Equips(5, name=u'鞋子', level=1, speed=2, strength=2))
        
        self.player1.delEquip(4)        #卸载裤子
        self.assertEqual(self.player1.maxhp, 440)
        self.assertEqual(self.player1.maxmp,279)
        self.assertEqual(int(self.player1.atk),71)
        self.assertEqual(int(self.player1.defend),64)
        self.assertEqual(int(self.player1.dexterity),42)
        self.assertEqual(int(self.player1.magic),35)
        
        self.player1.delEquip(2)        #卸载肩膀
        self.assertEqual(self.player1.maxhp, 440)
        self.assertEqual(self.player1.maxmp,279)
        self.assertEqual(int(self.player1.atk),69)
        self.assertEqual(int(self.player1.defend),62)
        self.assertEqual(int(self.player1.dexterity),42)
        self.assertEqual(int(self.player1.magic),35)
        
        self.player1.delEquip(0)        #卸载武器
        self.assertEqual(self.player1.maxhp, 440)
        self.assertEqual(self.player1.maxmp,279)
        self.assertEqual(int(self.player1.atk),59)
        self.assertEqual(int(self.player1.defend),62)
        self.assertEqual(int(self.player1.dexterity),42)
        self.assertEqual(int(self.player1.magic),35)
        
        self.player1.delEquip(5)        #卸载鞋子
        self.assertEqual(self.player1.maxhp, 428)
        self.assertEqual(self.player1.maxmp,271)
        self.assertEqual(int(self.player1.atk),59)
        self.assertEqual(int(self.player1.defend),58)
        self.assertEqual(int(self.player1.dexterity),38)
        self.assertEqual(int(self.player1.magic),35)
        
        self.player1.delEquip(3)        #卸载衣服
        self.assertEqual(self.player1.maxhp, 400)
        self.assertEqual(self.player1.maxmp,270)
        self.assertEqual(int(self.player1.atk),59)
        self.assertEqual(int(self.player1.defend),56)
        self.assertEqual(int(self.player1.dexterity),38)
        self.assertEqual(int(self.player1.magic),35)
        


if __name__ == '__main__':
    unittest.main()
    